<template>
	<view style="height: 100vh;width: 100%;">
		<web-view v-if="loading" :src="src"></web-view>
		<view v-else style="margin-top: 200rpx;width: 100%;text-align: center;">{{ $t('加载中') }}...</view>
	</view>
</template>

<script>
	import {
		IM_URL
	} from "@/config/app";
	import app from "@/main";

	export default {
		data() {
			return {
				// webviewStyles: {
				//   height: '100vh',
				//   weight: '100%'
				// },
				src: '',
				type: 'list',
				mobile: '',
				to_mobile: '',
				loading: false,
				iskf: false,
			};
		},
		onLoad(options) {
			if (!options.type) {
				var mobile = uni.getStorageSync('mobile');

				if (!mobile) {
					this.$u.toast(app.$i18n.t('请先登录'));
					setTimeout(() => {
						// 此为uView的方法，详见路由相关文档
						this.$u.route('/pages/user/login/login')
					}, 1000)
				}
				this.type = 'list'
				this.mobile = mobile
			} else {
				this.type = options.type
				this.mobile = options.mobile
			}
			this.iskf = options.iskf
			
			console.log("this.iskf",this.iskf,this.iskf == 'true' ? 'kf' : 'user')
			if (this.type === 'list') { // 消息列表
				console.log('im-list-mobile', this.mobile)
				this.src = IM_URL + "TUIKit/components/TUIConversation/index?mobile=" + this.mobile
				this.loading = true
			} else { // 会话详情
				console.log('im-detail-mobile', this.mobile)
				console.log('im-detail-to_mobile', options.to_mobile)
				this.to_mobile = options.to_mobile
				this.src = IM_URL + "TUIKit/components/TUIChat/index?mobile=" + this.mobile + '&to_mobile=' + this
					.to_mobile + '&type=' + (this.iskf == 'true' ? 'kf' : 'user')
					console.log(this.src)
				this.loading = true
			}
			console.log("web-view-src", this.src)
		},
	}
</script>

<style lang="scss">

</style>